<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">选择仓库：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="warehouseId" lay-filter="warehouseId" id="inWarehouseNameSelect">
                                            <option value="">选择仓库</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">入库类型：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="storageType" lay-filter="storageType">
                                            <option value="">按入库类型</option>
                                            <option value="production">生产入库</option>
                                            <option value="allot">调拨入库</option>
                                            <option value="salesreturn">退货入库</option>
                                            <option value="barter">换货入库</option>
                                            <option value="breakage">报损入库</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料类型：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="productTypeId" lay-filter="productTypeId" id="productTypeIdOption">
                                            <option value="">选择物料类型</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">作业编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="code" class="layui-input" type="text" placeholder="入库作业单编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">计划编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="planCode" class="layui-input" type="text" placeholder="入库计划编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" id="storageRecordSearch" lay-filter="storageRecordSearch" lay-submit>查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="storageWorkRecordBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="inventoryInoutJobTable" lay-filter="inventoryInoutJobTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="inventoryInoutJobTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="workDetail">查看详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="workPrint">打印</a>
</script>

<script type="text/html" id="storageProductTableBar">
    {{# if(d.status =="unreceipted"){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="confirmSign">确定签收</a>
    {{# } }}
</script>
<!-- 表单添加弹窗 -->
<script type="text/html" id="inventoryInoutJobForm">

    <form lay-filter="inventoryInoutJobForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div id="workCodeSpan" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库作业编号</label>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red" id="workCode"></span>
            </div>
        </div>
        <div id="storagePlanSelect" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;margin-left: 2px;">
                <span style="color: red">*</span>所属入库计划
            </label>
            <div class="layui-input-block" style="width: 200px;margin-left: 132px;">
                <select name="storagePlanCode" id="storagePlanCode" lay-filter="storagePlanCode" required lay-verify="required" placeholder="请选择所属入库计划">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div id="planCodeSpan" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>所属入库计划</label>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red" id="planCode"></span>
            </div>
        </div>

        <div id="storageInfoAll" style="display: none">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;">计划提交时间</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="planCreateTime"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;">入库类型</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="storagetypeDesc1"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;">生产计划工单</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="productionPlanCode"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>物料生产部门</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="productionDepartment"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>生产台机工位</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="productionMachine"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>生产负责人</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="manufactureHeadName"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>物料物料名称</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="skuCode"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;">送料数量</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="feedQuantity"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库单位</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="storageUnitName"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库包装方案</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="pageScheme"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库送料人</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="feedingPeople"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库仓库</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="warehouseName"></span>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">签收包装SN码</label>
        </div>
        <table class="layui-table" id="pageSnTable" lay-filter="pageSnTable"></table>
        <div class="layui-form-item" id="signProductBtn" style="display: none">
            <label class="layui-form-label" style="width: 100px;"></label>
            <div class="layui-form-mid layui-word-aux">
                <button id="storageProductBtnAdd" type="button" class="layui-btn icon-btn"><i
                        class="layui-icon">&#xe654;</i>添加入库签收物料信息
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>总签收数</label>
            <div class="layui-form-mid layui-word-aux">
                            <span style="color: red" id="amount">0</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库签收人</label>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red" id="userName"></span>
            </div>
        </div>

        <div id="signStationNameSelect" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;padding-left: 16px;"><span
                    style="color: red">*</span>入库签收工位</label>
            <div class="layui-input-block" style="width: 200px;margin-left: 132px;">
                <input type="text" name="signStationName" lay-verify="required" placeholder="入库签收工位" autocomplete="off"
                       class="layui-input">
            </div>
            <!--<div class="layui-input-block" style="width: 200px;margin-left: 132px;">
                <select name="signStationId" required lay-verify="required" placeholder="请选择入库签收工位">
                    <option value="">入库签收工位</option>
                    <option value="1">CPC-01</option>
                    <option value="2">CPC-02</option>
                </select>
            </div>-->
        </div>
        <div id="signStationNameSpan" class="layui-form-item"style="display: none">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库签收工位</label>
            <div class="layui-form-mid layui-word-aux">
                            <span style="color: red" id="signStationName">CPC-02</span>
            </div>
        </div>
        <div id="createTimeSpan" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库签收时间</label>
            <div class="layui-form-mid layui-word-aux">
                            <span style="color: red" id="createTime"></span>
            </div>
        </div>
        <!--style="margin-top: 20px;display: none"-->
        <div id="remarkInput" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px">入库备注说明</label>
            <div class="layui-input-block" style="width: 200px;margin-left: 132px;">
                <input type="text" name="remark" placeholder="请输入入库备注说明" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div id="workRemarkSpan" class="layui-form-item" style="display: none">
            <label class="layui-form-label" style="width: 100px;">入库签收备注</label>
            <div class="layui-form-mid layui-word-aux">
                            <span style="color: red" id="workRemark"></span>
            </div>
        </div>
        <div class="layui-form-item" id="storageRecordBtn" style="display: none">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="storageWorkSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</script>
<!-- 添加入库作业签收物料弹窗 -->
<script type="text/html" id="addStorageProductModel">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="addStorageProductForm">
                    <div class="layui-form-item" style="margin-top: 20px;">
                        <label class="layui-form-label">扫描包装码</label>
                        <div class="layui-inline">
                            <input name="packCode" class="layui-input" type="text" placeholder="请输入包装码编号"/>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" type="button" id="addProductSingSearch" lay-submit lay-filter="addProductSingSearch">添加签收信息</button>
                        </div>
                    </div>

                </form>
                <table class="layui-table" id="storageProductTable" lay-filter="storageProductTable"></table>
                <div class="layui-form-item" style="margin-top: 20px;text-align: center;">
                    <div class="layui-inline">
                        <button id="productConfirmBtn" type="button" class="layui-btn icon-btn">确定提交 </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 表格 -->
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var planId = "";//入库计划id
        var type = 0; //0是添加 1是查看详情
        var pageSnList = [];
        var planCode = "";//入库计划code
        var storageTypeDesc = "";//入库类型
        var productPackLabeList = [];//入库签收物料签收信息
        var packLabelIdList = [];
        var amount = 0;//总签收数
        var workData = null;
        var skuCode = "";//用于接收出库计划物料的skuCode 在物料包装码数据点击签收时校验是否是出库计划的物料
        //查询仓库
        admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0){
                    $.each(res.data,function (index,item) {
                        $("#inWarehouseNameSelect").append(new Option(item.name,item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');
        //查询物料类型
        admin.req('enterprise/product/admin/productType/getProductTypeVOAll', {}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0){
                    $.each(res.data,function (index,item) {
                        $("#productTypeIdOption").append(new Option(item.name,item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');
        // 渲染表格
        var insTb = table.render({
            elem: '#inventoryInoutJobTable',
            url: config.base + 'enterprisecab/order/admin/inventoryInoutJob/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'}
                ,{field: 'number', title: '序号', width: 60, type: 'numbers'}
                , {field: 'id', title: 'ID', width: 60, hide: true}
                ,{field: 'code', sort: true, title: '入库作业单编号', width: 180}
                ,{field: 'planCode', sort: true, title: '入库计划单编号', width: 180}
                ,{field: 'skuCode', sort: true, title: '物料编号', width: 150}
                ,{field: 'productType', sort: true, title: '物料类型', width: 100}
                ,{field: 'storageTypeDesc', sort: true, title: '入库类型', width: 100}
                ,{field: 'unitName', sort: true, title: '单位名称', width: 100}
                ,{field: 'quantity', sort: true, title: '入库数量'}
                ,{field: 'warehouseName', sort: true, title: '入库仓库'}
                ,{field: 'createTime', sort: true, title: '入库时间', width: 150}
                ,{field: 'statusDesc', sort: true, title: '状态',templet(d) {
                    return "已入库";
                }}
                ,{align: 'center', toolbar: '#inventoryInoutJobTableBar', title: '操作', width: 150}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });
        form.render('select');
        // 工具条点击事件
        table.on('tool(inventoryInoutJobTable)', function (obj) {
            workData = obj.data;
            if (obj.event === 'workDetail') { //详情
                type = 1;
                showEditModel(workData,type);
            } else if (obj.event === 'workPrint') { // 打印
                doDelete(obj);
            }
        });

        //监听排序
        table.on('sort(inventoryInoutJobTable)', function(obj){
            table.reload('inventoryInoutJobTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(storageRecordSearch)', function (data) {
            insTb.reload({
                where: data.field, page: {curr: 1}
            })
            return false;
        });

        // 添加按钮点击事件
        $('#storageWorkRecordBtnAdd').click(function () {
            type = 0;
            showEditModel(workData,type);
        });

        // 显示添加编辑弹窗
        function showEditModel(data,type) {
            var index = admin.open({
                type: 1,
                area: ['1400px', '800px'],
                offset: '65px',
                title: data ? '修改入库作业单记录' : '添加入库作业单记录',
                content: $('#inventoryInoutJobForm').html(),
                success: function () {
                    pageSnList = [];//清空签收包装SN码
                    productPackLabeList = [];
                    amount = 0;//清空总数
                    if(type == 0){//添加
                        let userName = config.getUser().nickname;
                        $("#userName").html(userName);
                        //查询所有入库计划
                        admin.req('enterprisecab/order/admin/inventoryInoutJob/getStoragePlanAll', {}, function (res) {
                            if (res.code == 200) {
                                if (res.data.length > 0){
                                    $.each(res.data,function (index,item) {
                                        $("#storagePlanCode").append(new Option(item.code,item.id));
                                    })
                                    form.render('select');
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        $("#storagePlanSelect").show();
                        $("#signStationNameSelect").show();
                        $("#remarkInput").show();
                        $("#signProductBtn").show();
                        $("#storageRecordBtn").show();

                    }else{
                        $("#storageInfoAll").show();
                        $("#planCodeSpan").show();
                        $("#signStationNameSpan").show();
                        $("#createTimeSpan").show();
                        $("#workRemarkSpan").show();
                        $("#workCodeSpan").show();
                        admin.req('enterprisecab/order/admin/inventoryInout/getInventoryInoutById', {id:data.planId}, function (res) {
                            if (res.code == 200) {
                                planId = res.data.id;
                                planCode = res.data.code;
                                storageTypeDesc = res.data.storageTypeDesc;
                                $("#workCode").html(data.code);
                                $("#storagetypeDesc1").html(res.data.storageTypeDesc);
                                $("#planCreateTime").html(res.data.createTime);
                                $("#productionPlanCode").html(res.data.productionPlanCode);
                                $("#productionDepartment").html(res.data.productionDepartment);
                                $("#productionMachine").html(res.data.productionMachine);
                                $("#manufactureHeadName").html(res.data.manufactureHeadName);
                                $("#skuCode").html(res.data.skuCode);
                                $("#feedQuantity").html(res.data.feedQuantity);
                                $("#storageUnitName").html(res.data.unitName);
                                $("#pageScheme").html(res.data.pageScheme);
                                $("#feedingPeople").html(res.data.feedingPeople);
                                $("#warehouseName").html(res.data.warehouseName);
                                $("#planCode").html(res.data.code);
                                $("#userName").html(res.data.creatorName);
                                $("#createTime").html(data.createTime);
                                $("#workRemark").html(data.remark);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        //查询入库单
                        admin.req('enterprisecab/order/admin/inventoryInoutJob/getInventoryInoutJobById', {id: data.id}, function (res) {
                            if (res.code == 200) {
                                $("#signStationName").html(res.data.signStationName);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        admin.req('enterprisecab/order/admin/inventoryJob/getJobProductList', {jobId: data.id}, function (res) {
                            if (res.code == 200) {
                                pageSnList = res.data;
                                for (let i = 0; i < pageSnList.length ; i++) {
                                    pageSnList[i].storageTypeDesc = storageTypeDesc;
                                    amount = parseInt(amount) + parseInt(pageSnList[i].quantity);
                                    $("#amount").html(amount);
                                }
                                table.reload('pageSnTable',{
                                    data: pageSnList,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }
                    //监听入库计划select
                    form.on('select(storagePlanCode)', function(data){
                        admin.req('enterprisecab/order/admin/inventoryInout/getInventoryInoutById', {id:data.value}, function (res) {
                            if (res.code == 200) {
                                $("#storageInfoAll").show();//选择了入库计划再显示
                                planId = res.data.id;
                                planCode = res.data.code;
                                skuCode = res.data.skuCode;
                                storageTypeDesc = res.data.storageTypeDesc;
                                $("#storagetypeDesc1").html(res.data.storageTypeDesc);
                                $("#planCreateTime").html(res.data.createTime);
                                $("#productionPlanCode").html(res.data.productionPlanCode);
                                $("#productionDepartment").html(res.data.productionDepartment);
                                $("#productionMachine").html(res.data.productionMachine);
                                $("#manufactureHeadName").html(res.data.manufactureHeadName);
                                $("#skuCode").html(res.data.skuCode);
                                $("#feedQuantity").html(res.data.feedQuantity);
                                $("#storageUnitName").html(res.data.unitName);
                                $("#pageScheme").html(res.data.pageScheme);
                                $("#feedingPeople").html(res.data.feedingPeople);
                                $("#warehouseName").html(res.data.warehouseName);
                                $("#planCode").html(res.data.code);
                                $("#userName").html(res.data.creatorName);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    });
                    var storageRecordTable = table.render({
                        elem: '#pageSnTable',
                        data: pageSnList,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'number', title: '序号', width: 60, type: 'numbers'}
                            , {field: 'id', title: 'ID', width: 60, hide: true}
                            , {field: 'packLabelCode', sort: true, title: '包装SN编号', width: 150}
                            , {field: 'skuCode', sort: true, title: '物料编号', width: 120}
                            , {field: 'skuSpecCode', sort: true, title: '物料规格码', width: 150}
                            , {field: 'packCode', title: '规格描述'}
                            , {field: 'storageTypeDesc', title: '入库类型'}
                            , {field: 'unitName', title: '最小单位'}
                            , {field: 'quantity', title: '入库数量'}
                            , {field: 'createTime', title: '录入时间'}
                            , {field: 'statusDesc', title: '状态', templet(d) {
                                    return "已签收"
                                }}
                            //,hide : type == 0 ? true : false
                        ]]
                    });
                    //添加入库物料签收信息
                    $("#storageProductBtnAdd").click(function () {
                        showAddStorageProductModel();
                    })
                    //入库作业单提交
                    form.on('submit(storageWorkSubmit)', function (data) {
                        if(packLabelIdList.length == 0){
                            layer.msg("请先选择签收物料", {icon: 2});
                            return false;
                        }
                        let signStationId = data.field.signStationId;
                        let signStationName = data.field.signStationName;
                        let remark = data.field.remark;
                        let pageSnListNew = pageSnList.map(item => {
                            return {packLabeId:item.packLabeId,packLabeCode:item.packLabelCode,skuCode:item.skuCode,skuSpecCode:item.skuSpecCode,
                                unitName:item.unitName,unitId:item.unitId,quantity:item.quantity,packName:item.packCode,packId:item.packId
                            };
                        })
                        let productJson = JSON.stringify(pageSnListNew);
                        console.log(productJson)
                        admin.req('enterprisecab/order/admin/inventoryInoutJob/addInventoryInoutJob', {planId: planId,signStationId:signStationId,
                            remark:remark,quantity:amount,productJson:productJson,signStationName:signStationName}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                layer.close(index);//关闭窗口
                                //刷新入库作业表格
                                table.reload('inventoryInoutJobTable',{
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'post');
                        return false;
                    });
                }
            });
        }


        // 添加入库签收物料信息弹窗
        function showAddStorageProductModel() {
            var productIndex = admin.open({
                type: 1,
                area: ['1300px', '600px'],
                offset: '115px',
                title: '添加入库计划物料详细信息',
                content: $('#addStorageProductModel').html(),
                success: function () {
                    form.on('submit(addProductSingSearch)', function (obj) {
                        if(obj.field.packCode == ""){
                            layer.msg("请输入包装条码", {icon: 2});
                            return false;
                        }
                        if(productPackLabeList.length > 0){
                            for (let i = 0; i < productPackLabeList.length; i++) {
                                if(obj.field.packCode == productPackLabeList[i].code){
                                    layer.msg("包装条码已存在当前列表", {icon: 2});
                                    return false;
                                }
                            }
                        }
                        admin.req('enterprise/product/admin/productPackLabel/getProductPackLabelVOList', {code:obj.field.packCode,type:0}, function (res) {
                            if (res.code == 200) {
                                let packLabeList = res.data;
                                    packLabeList.planCode = planCode;
                                    packLabeList.quantityOut = packLabeList.surplusQuantity;
                                    packLabeList.status = "unreceipted";//默认未签收
                                    productPackLabeList.push(packLabeList);
                                table.reload('storageProductTable',{
                                    data: productPackLabeList,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        return false;
                    });
                    //判断pageSnList是否有数据，有则根据code相同将状态改为sign
                    if(pageSnList.length > 0){
                        for (let i = 0; i < productPackLabeList.length; i++) {
                            for (let j = 0; j < pageSnList.length; j++) {
                                if(productPackLabeList[i].code == pageSnList[j].packLabelCode){
                                    productPackLabeList[i].status = "sign";
                                    productPackLabeList[i].quantityOut = pageSnList[j].quantity;
                                }
                            }
                        }
                        table.reload('storageProductTable',{
                            data: productPackLabeList,
                        })
                    }
                    var storageProductTable = table.render({
                        elem: '#storageProductTable',
                        data: productPackLabeList,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'number', title: '序号', width: 60, type: 'numbers'}
                            , {field: 'id', title: 'ID', width: 60, hide: true}
                            , {field: 'status', title: 'status', width: 60, hide: true}
                            , {field: 'code', sort: true, title: '包装编码', width: 150}
                            , {field: 'planCode', sort: true, title: '所属入库计划', width: 120}
                            , {field: 'productName', sort: true, title: '物料名称', width: 120}
                            , {field: 'skuCode', sort: true, title: '物料编号'}
                            , {field: 'packName', title: '包装规格'}
                            , {field: 'quantity', title: '单位包装数'}
                            , {field: 'unitName', title: '最小单位'}
                            , {field: 'quantity', title: '本SN码应收数'}
                            , {field: 'quantityOut', title: '本SN码签收数'}
                            , {align: 'center', toolbar: '#storageProductTableBar', title: '操作', width: 150}//,hide : type == 0 ? true : false
                        ]]
                        ,done: function(res, curr, count){
                            let tableView = this.elem.next();
                            layui.each(res.data, function (i, item) {
                                if (item.status === 'unreceipted') {
                                    tableView.find('tr[data-index=' + i + ']').find('td').eq(11).data('edit', true); //设置下标为9的单元格为可编辑
                                }
                            })

                        }
                    });
                    //编辑单元格事件
                    table.on('edit(storageProductTable)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
                       /* console.log(obj.value); //得到修改后的值
                        console.log(obj.field); //当前编辑的字段名
                        console.log(obj.data); //所在行的所有相关数据*/
                        if(obj.value > obj.data.quantity){
                            layer.msg("不能大于本SN码应收数",{icon: 2});
                            table.reload('storageProductTable',{
                                data: productPackLabeList,
                            })
                            return false;
                        }
                        const row = productPackLabeList.find(x => x.id === obj.data.id);
                        if(row){
                            row.quantityOut = obj.value;
                            table.reload('storageProductTable',{
                                data: productPackLabeList,
                            })
                        }
                        layer.msg("修改成功");
                    });
                    // 工具条点击事件
                    table.on('tool(storageProductTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'confirmSign') { //确定签收
                            if(skuCode != data.skuCode){
                                layer.msg("当前物料不是入库计划里的物料，不能签收！",{icon: 2});
                                return false;
                            }
                            if(data.quantityOut > data.surplusQuantity){
                                layer.msg("不能大于本SN码应收数",{icon: 2});
                                table.reload('storageProductTable',{
                                    data: productPackLabeList,
                                })
                                return false;
                            }
                            //const row = productPackLabeList.find(x => x.id === obj.data.id);
                            for (let i = 0; i < productPackLabeList.length; i++) {
                                if(productPackLabeList[i].id == data.id){
                                    productPackLabeList[i].status = "sign";
                                }
                            }
                            table.reload('storageProductTable',{
                                data: productPackLabeList,
                            })
                            packLabelIdList.push(data.id);

                        } else if (obj.event === 'updateSign') { // 修改

                        }
                    });
                    $("#productConfirmBtn").click(function () {

                        if(packLabelIdList.length == 0){
                            layer.msg("请先签收", {icon: 2});
                            return false;
                        }
                        admin.req('enterprisecab/order/admin/inventoryJob/getSignPackSnList', {packLabelIdList: packLabelIdList}, function (res) {
                            if (res.code == 200) {
                                pageSnList = res.data;
                                amount = 0;
                                for (let i = 0; i < productPackLabeList.length; i++) {
                                    for (let j = 0; j < pageSnList.length; j++) {
                                        if(productPackLabeList[i].code == pageSnList[j].packLabelCode){
                                            pageSnList[j].quantity = productPackLabeList[i].quantityOut;
                                            amount = parseInt(amount) + parseInt(productPackLabeList[i].quantityOut);
                                            pageSnList[j].storageTypeDesc = storageTypeDesc;//入库类型
                                        }
                                    }
                                }
                                $("#amount").html(amount);//总签收赋值
                                //去重数据
                                let nArr = pageSnList.filter((currentValue, currentIndex, selfArr) => {
                                    return selfArr.findIndex(x =>x.skuCode === currentValue.skuCode) === currentIndex
                                });

                                let newData = [];
                                newData.push(JSON.parse(JSON.stringify(nArr[0])))
                                newData[0].quantity = amount;
                                layer.close(productIndex);//关闭最新打开的窗口
                                //确认提交签收的物料信息，重载pageSnTable
                                table.reload('pageSnTable',{
                                    data: newData,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    })
                }
            });
            form.render();
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/order/admin/inventoryInoutJob/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#inventoryInoutJobBtnExport').click(function () {
            var checkRows = table.checkStatus('inventoryInoutJobTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>